import { createRouter, createWebHistory } from "vue-router";
import { localCache } from "@/ults/cache.js";
const routes = [
  {
    path: "/",
    redirect: "/main",
  },
  {
    path: "/login",
    name: "login",
    meta: {
      name: "登录",
    },
    component: () => import("../views/login/login.vue"),
  },
  {
    path: "/main",
    name: "main",
    meta: {
      name: "首页",
    },
    component: () => import("../views/main/main.vue"),
    children: [
      {
        path: "/main",
        redirect: "/main/home",
      },
      {
        path: "/main/home",
        meta: {
          name: "首页",
        },
        component: () => import("../views/main/home/home.vue"),
      },
      {
        path: "/main/user",
        meta: {
          name: "用户管理",
        },
        component: () => import("../views/main/user/user.vue"),
      },
      {
        path: "/main/role",
        meta: {
          name: "角色管理",
        },
        component: () => import("../views/main/role/role.vue"),
      },
      {
        path: "/main/menu",
        meta: {
          name: "菜单管理",
        },
        component: () => import("../views/main/menu/menu.vue"),
      },
      {
        path: "/main/rich",
        meta: {
          name: "富文本",
        },
        component: () => import("../views/main/rich/rich.vue"),
      },
      {
        path: "/main/news",
        meta: {
          name: "新闻",
        },
        component: () => import("../views/main/news/news.vue"),
      },
	  {
	    path: "/main/users",
	    meta: {
	      name: "小程序用户",
	    },
	    component: () => import("../views/main/users/users.vue"),
	  },
	  {
	    path: "/main/counselor",
	    meta: {
	      name: "咨询师",
	    },
	    component: () => import("../views/main/counselor/counselor.vue"),
	  },
    ],
  },
];
const router = createRouter({
  history: createWebHistory(),
  routes: routes,
});
router.beforeEach((to, from, next) => {
  if (to.path != "/login" && !localCache.getCache("token")) {
    next("/login");
  }
  next();
});
export default router;
